﻿using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class BaseDal<T> : IBaseDal<T> where T : class
    {
        public BaseDal(MyContext context)
        {
            Context = context;
        }

        public MyContext Context { get; }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public async Task<int> AddAsync(T t)
        {
            await Context.Set<T>().AddAsync(t);
            return await Context.SaveChangesAsync();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public async Task<int> DelAsync(T t)
        {
            Context.Set<T>().RemoveRange(t);
            return await Context.SaveChangesAsync();
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public IQueryable<T> GetAsync()
        {
            return Context.Set<T>();
        }
    }
}
